package top.api.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.api.common.ResUlt;
import top.api.domain.dto.PageDto;
import top.api.domain.pojo.Student;
import top.api.service.impl.StudentServiceImpl;

import java.util.List;

@RestController
@RequestMapping("/student")
@RequiredArgsConstructor
public class StudentController {

    private final StudentServiceImpl studentService;

    @GetMapping("/list")
//    @SaCheckRole("admin")
    @ApiOperation("分页查询")
    public ResUlt<?> listPage(PageDto pageDto, Integer id, String name){
        return studentService.listPage(pageDto,id,name);
    }


    @PostMapping("/addStudent")
    @SaCheckRole("admin")
    @ApiOperation("添加学生信息")
    public ResUlt<?> add(@RequestBody Student student){
        return studentService.add(student);
    }


    @GetMapping("{id}")
    @ApiOperation("获取学生信息信息")
    public ResUlt<?> getOne(@PathVariable Integer id){
        return studentService.getOne(id);
    }

    @DeleteMapping("{id}")
    @SaCheckRole("admin")
    @ApiOperation("删除学生信息")
    public ResUlt<?> delete(@PathVariable List id){
        return studentService.delete(id);
    }

    @PutMapping("/upStudent")
    @SaCheckRole("admin")
    @ApiOperation("更新学生信息信息")
    public ResUlt<?> updateUser(@RequestBody Student student){
        return studentService.changeStudent(student);
    }

    @PutMapping("/status")
    @SaCheckRole("admin")
    @ApiOperation("封禁学生账号信息")
    public ResUlt<?> changeStatus(@RequestBody Student student){
        return studentService.changeStatus(student);
    }

}
